﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using MacomberMapSystem.Common.Integration;

namespace MacomberMapSystem.Common.User_Interfaces.Mapping
{
    /// <summary>
    /// This class holds the network map representation of a boundary
    /// </summary>
    public class MM_NetworkMap_Boundary
    {
        #region Variable Declarations
        /// <summary>The graphics path used to draw the county at the current zoom level</summary>
        public GraphicsPath CountyPath;

        /// <summary>The boundary driving this component</summary>
        public MM_Boundary BaseBoundary;

        /// <summary>Whether the boundary is visible</summary>
        public bool Visible = false;
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize a new graphic representation of a boundary
        /// </summary>
        /// <param name="BaseBoundary">The boundary upon which the graphical representation is based</param>
        /// <param name="Coordinates">The coordinate scheme</param>
        public MM_NetworkMap_Boundary(MM_Boundary BaseBoundary, MM_NetworkMap_Display Coordinates)
        {
            this.BaseBoundary = BaseBoundary;
            ComputeCounty(Coordinates);
        }

        /// <summary>
        /// Compute the county at our current zoom level
        /// </summary>
        /// <param name="Coordinates">Our coordinates</param>
        public void ComputeCounty(MM_NetworkMap_Display Coordinates)
        {
            List<Point> CurPixels = new List<Point>();
            Point LastPoint = Point.Empty;
            if (BaseBoundary.Coordinates != null)
                foreach (PointF LatLng in BaseBoundary.Coordinates)
                {
                    Point InPoint = MM_NetworkMap_Display.LatLngToXY(LatLng, Coordinates.ZoomLevel);
                    if (InPoint != LastPoint)
                        CurPixels.Add(InPoint);
                    LastPoint = InPoint;
                }

            CountyPath = new GraphicsPath();
            CountyPath.AddLines(CurPixels.ToArray());
        }

        #endregion

        #region Hit testing
        /// <summary>
        /// Handle the hit test of the boundary
        /// </summary>
        /// <param name="PixelXY"></param>
        /// <returns></returns>
        public bool HitTest(Point PixelXY)
        {
            return CountyPath.IsVisible(PixelXY);
        }
        #endregion

    }
}
